//package com.sundi.ecgateway.config;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//@Component
//public class CrossOriginFilter implements GlobalFilter {
//
//    private static Logger logger = LoggerFactory.getLogger(CrossOriginFilter.class);
//
//    private static final String ALL = "*";
//    private static final String MAX_AGE = "18000L";
//
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange serverWebExchange, GatewayFilterChain gatewayFilterChain) {
//        ServerHttpRequest request = serverWebExchange.getRequest();
//        ServerHttpResponse response = serverWebExchange.getResponse();
//        HttpHeaders headers = response.getHeaders();
//        headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
//        headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "POST, GET, PUT, OPTIONS, DELETE, PATCH");
//        headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
//        headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "*");
//        headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, ALL);
//        headers.add(HttpHeaders.ACCESS_CONTROL_MAX_AGE, MAX_AGE);
//        if (request.getMethod() == HttpMethod.OPTIONS) {
//            response.setStatusCode(HttpStatus.OK);
//            return Mono.empty();
//        }
//        return gatewayFilterChain.filter(serverWebExchange);
//    }
//
//}
//
